package com.manager.user.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.manager.common.result.Result;
import com.manager.model.model.User;
import com.manager.user.service.UserUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/user")
@Api(description = "用户管理")
@CrossOrigin(origins = "*")
public class SellerController {

    @Autowired
    private UserUserService userService;

    @ApiOperation(value = "分页查询销售")
    @GetMapping("/page/{page}/{pageSize}")
    public Result<Page> getSellerPage(@PathVariable int page, @PathVariable int pageSize){
          return userService.pageSellers(page,pageSize);
    }

    @ApiOperation(value = "添加销售")
    @PostMapping("/add")
    public Result<String> addSeller(@RequestBody User user){
        return userService.addSeller(user);
    }

    @ApiOperation(value = "修改销售")
    @PutMapping("/modify")
    public Result<String> modifySeller(@RequestBody User user){
            return userService.modifySellerInfo(user);
    }

    @ApiOperation(value = "批量禁用销售人员")
    @PostMapping("/disable")
    public Result<String> disableSellers(@RequestParam List<String> ids){
        return userService.disableSellers(ids);
    }

    @ApiOperation(value = "批量启用销售人员")
    @PostMapping("/able")
    public Result<String> ableSellers(@RequestParam List<String> ids){
        return userService.ableSellers(ids);
    }

    @ApiOperation(value="导出销售人员信息")
    @GetMapping("/export")
    public void exportCustomer(HttpServletResponse response){
        userService.export(response);
    }
}
